package jhunter.dao.dialect;

import java.util.List;

import jhunter.dao.bo.BaseObject;
import jhunter.dao.page.Page;

public class MysqlDialect implements Dialect {

	public String page(Page<BaseObject> page, String sql, List<Object> params) {
		String retSql = sql + " limit ?, ? ";
		appendSqlParameters(page, params);
		return retSql;
	}

	protected void appendSqlParameters(Page<BaseObject> page, List<Object> params) {
		params.add(getFirstParameter(page));
		params.add(getSecondParameter(page));
	}

	public String getHibernateDialectClassName() {
		return "org.hibernate.dialect.MySQLDialect";
	}

	@Override
	public int getFirstParameter(Page<BaseObject> page) {
		return page.getFirst() - 1;
	}

	@Override
	public int getSecondParameter(Page<BaseObject> page) {
		return page.getPageSize();
	}

}
